/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:23:00 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class PhuonganDAL : SqlProvider<PhuonganEntity>
    {
        static PhuonganDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                PhuonganEntity entity = new PhuonganEntity();
				entity.PK_iPhuonganID = Int64.Parse("0"+dr["PK_iPhuonganID"].ToString());
				entity.sNoidung = dr["sNoidung"].ToString();
				entity.bDung =String.IsNullOrEmpty(dr["bDung"].ToString())?false:Boolean.Parse(dr["bDung"].ToString());
				entity.dNgaytao =String.IsNullOrEmpty(dr["dNgaytao"].ToString())?DateTime.Now:DateTime.Parse(dr["dNgaytao"].ToString());
				entity.dNgaycapnhat =String.IsNullOrEmpty(dr["dNgaycapnhat"].ToString())?DateTime.Now:DateTime.Parse(dr["dNgaycapnhat"].ToString());
				entity.FK_iNguoitao = Int64.Parse("0"+dr["FK_iNguoitao"].ToString());
				entity.FK_iNguoicapnhat = Int64.Parse("0"+dr["FK_iNguoicapnhat"].ToString());
				entity.FK_iDanhmuccauhoiID = Int16.Parse("0"+dr["FK_iDanhmuccauhoiID"].ToString());
                return entity;
            };
        }
        public static PhuonganEntity GetOne(Int64 PK_iPhuonganID)
        {
            string cmdName = "spPhuongan_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iPhuonganID", PK_iPhuonganID);
            PhuonganEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<PhuonganEntity> GetAll()
        {
            string cmdName = "spPhuongan_Get";
            return GetList(cmdName);
        }
        public static List<PhuonganEntity> GetByFK_iNguoitao(Int64 FK_iNguoitao)
		{
			string cmdName = "spPhuongan_GetByFK_FK_iNguoitao";
			SqlParameter p = new SqlParameter("@FK_iNguoitao",FK_iNguoitao);
			List<PhuonganEntity> list = GetList(cmdName, p);
			return list;
		}public static List<PhuonganEntity> GetByFK_iNguoicapnhat(Int64 FK_iNguoicapnhat)
		{
			string cmdName = "spPhuongan_GetByFK_FK_iNguoicapnhat";
			SqlParameter p = new SqlParameter("@FK_iNguoicapnhat",FK_iNguoicapnhat);
			List<PhuonganEntity> list = GetList(cmdName, p);
			return list;
		}public static List<PhuonganEntity> GetByFK_iDanhmuccauhoiID(Int16 FK_iDanhmuccauhoiID)
		{
			string cmdName = "spPhuongan_GetByFK_FK_iDanhmuccauhoiID";
			SqlParameter p = new SqlParameter("@FK_iDanhmuccauhoiID",FK_iDanhmuccauhoiID);
			List<PhuonganEntity> list = GetList(cmdName, p);
			return list;
		}
        public static int Add(PhuonganEntity entity)
        {
            string cmdName = "spPhuongan_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(PhuonganEntity entity)
        {
            string cmdName = "spPhuongan_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iPhuonganID)
        {
            string cmdName = "spPhuongan_Delete";
            SqlParameter p = new SqlParameter("@PK_iPhuonganID", PK_iPhuonganID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(PhuonganEntity entity)
        {
            SqlParameter[] p = new SqlParameter[8];
			p[0] = new SqlParameter("@PK_iPhuonganID", entity.PK_iPhuonganID);
			p[1] = new SqlParameter("@sNoidung", entity.sNoidung);
			p[2] = new SqlParameter("@bDung", entity.bDung);
			p[3] = new SqlParameter("@dNgaytao", entity.dNgaytao);
			p[4] = new SqlParameter("@dNgaycapnhat", entity.dNgaycapnhat);
			p[5] = new SqlParameter("@FK_iNguoitao", entity.FK_iNguoitao);
			p[6] = new SqlParameter("@FK_iNguoicapnhat", entity.FK_iNguoicapnhat);
			p[7] = new SqlParameter("@FK_iDanhmuccauhoiID", entity.FK_iDanhmuccauhoiID);
            return p;
        }
        #endregion
       
    }
}